﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Shell32;

namespace QTMusic.BaseClasses
{
    public class song
    {
        private int id;
        private string name;
        private string artist;
        private string genre;
        private DateTime releaseDate;
        private string length;
        private int bitrate;
        private string path;
        private int playCount;
        private int downloadCount;
        private int likeCount;
        private string description;

        public int _id
        {
            get { return this.id;}
            set { this.id = value; }
        }
        public string _name
        {
            get { return this.name; }
            set { this.name = value; }
        }

        public DateTime _releaseDate
        {
            get { return this.releaseDate; }
            set { this.releaseDate = value; }
        }

        public string _artist
        {
            get { return this.artist; }
            set { this.artist = value; }
        }

        public string _genre
        {
            get {return this.genre;}
            set { this.genre = value;}
        }

        public string _length
        {
            get { return this.length; }
            set { this.length = value; }
        }

        public int _bitrate
        {
            get { return this.bitrate; }
            set { this.bitrate = value; }
        }

        public string _path
        {
            get { return this.path; }
            set { this.path = value; }
        }

        public int _playCount
        {
            get { return this.playCount; }
            set { this.playCount = value; }
        }

        public int _downloadCount
        {
            get { return this.downloadCount; }
            set { this.downloadCount = value; }
        }

        public int _likeCount
        {
            get { return this.likeCount; }
            set { this.likeCount = value; }
        }

        public string _description
        {
            get { return this.description; }
            set { this.description = value; }
        }

        public static void GetMediaInfo(string DataFoldername, string DataFilename, out int bitrate, out string length)
        {
            int bitrateIndex = 28;
            int lengthIndex = 27;

            bitrate = 128;
            length = "00:04:00";

            Shell shell = new Shell();
            Folder objFolder;

            objFolder = shell.NameSpace(DataFoldername);

            /*
            for (int i = 0; i < short.MaxValue; i++)
            {
                string header = objFolder.GetDetailsOf(null, i);
                if (String.IsNullOrEmpty(header))
                    break;
                if (header.Contains("bitrate"))
                    bitrateIndex = i;
                if (header.Contains("length"))
                    bitrateIndex = i;
            }
            */
            
            FolderItem item = objFolder.ParseName(DataFilename);
            length = objFolder.GetDetailsOf(item, lengthIndex);
            string temp = objFolder.GetDetailsOf(item, bitrateIndex);
            int tempbitrate = 0;
            for (int i = 0; i < temp.Length; i++)
            {
                if (char.IsDigit(temp[i]))
                    tempbitrate = tempbitrate * 10 + temp[i] - 0x30;
            }
            if (tempbitrate != 0)
                bitrate = tempbitrate;

            return;
        }
    }
}